﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MobileBG
{
    public partial class Defauld : System.Web.UI.Page
    {
        private List<Producer> producers = new List<Producer>();
        private List<Extra> extr = new List<Extra>();         

        protected void Page_Load(object sender, EventArgs e)
        {

            producers.Add(
                    new Producer("Audi", new List<CarModel>()
                    {
                        new CarModel("A4"),
                        new CarModel("A5 Sport"),
                        new CarModel("A3"),
                        new CarModel("Audi 80")
                    }));
            producers.Add(
                    new Producer("VW", new List<CarModel>()
                    {
                        new CarModel("Polo"),
                        new CarModel("Golf 5"),
                        new CarModel("Golf 6 GTI"),
                        new CarModel("Passat")
                    }));
            producers.Add(
                    new Producer("BMW", new List<CarModel>()
                    {
                        new CarModel("3"),
                        new CarModel("6")
                    }));
            extr.Add(new Extra("AirCon"));
            extr.Add(new Extra("Rims"));
            extr.Add(new Extra("4x4"));
            extr.Add(new Extra("2(3) Doors"));
            extr.Add(new Extra("4(5) Doors"));
            extr.Add(new Extra("Something else"));

            string[] engines = { "diesel", "petrol" };

            if (!Page.IsPostBack)
            {
                producersDDL.DataSource = producers;
                modelDDL.DataSource = producers.First().Models;
                extrasCBL.DataSource = extr;
                enginesRBL.DataSource = engines;
                DataBind();
            }
        }

        protected void producersDDL_SelectedIndexChanged(object sender, EventArgs e)
        {
            modelDDL.DataSource = producers[this.producersDDL.SelectedIndex].Models;
            DataBind();
        }

        protected void submit_Click(object sender, EventArgs e)
        {
            Literal l = new Literal();
            l.Text = "<b>Producer: </b>" + producersDDL.SelectedValue + "<br/>";
            myPH.Controls.Add(l);
            l = new Literal();
            l.Text = "<b>Model: </b>" + modelDDL.SelectedValue + "<br/>";
            myPH.Controls.Add(l);
            l = new Literal();
            l.Text = "Extras: ";
            myPH.Controls.Add(l);
            for (int i = 0; i < extr.Count; i++)
            {
                if (extrasCBL.Items[i].Selected)
                {
                    l = new Literal();
                    l.Text = extr[i].Name + ", ";
                    myPH.Controls.Add(l);
                }
            }
            l = new Literal();
            l.Text = "<br/>Engine: ";
            myPH.Controls.Add(l);
            l = new Literal();
            l.Text = enginesRBL.SelectedValue;
            myPH.Controls.Add(l);
        }
    }
}